#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :updateDatas.py
# @Time      :2021/6/21 21:50
# @Author    : 刘广鸿

from url.urls import URLS
from config.config import shzx_app
from fastapi import Depends, status, Response
from sqlalchemy.orm import Session
from dbs import crud, mSession
from dbs import model
from dbs import schemas
from dbs.database import engine
import uuid
import hashlib
# import datetime
from time import time

"""
    Test for update password for post method：http://127.0.0.1:8000/updatepassword
    :param
        form
        {
                username: str
                token: str
                oldpassword: str
                newpassword: str
        }
    :return
        201 for update password success
        403 for update password fail
"""


@shzx_app.post(URLS[8])
def update_password(updatePasswordForm: schemas.UpdatePasswordForm, db: Session = Depends(mSession.get_db)):
    if crud.UpdatePassword(db, updatePasswordForm.username, updatePasswordForm.token
            , updatePasswordForm.oldpassword, updatePasswordForm.newpassword):
        return Response(status_code=status.HTTP_201_CREATED)
    else:
        return Response(status_code=status.HTTP_403_FORBIDDEN)
